package com.ruoyi.common.utils;

import com.ruoyi.common.constant.UserConstants;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created On : 2024/4/13.
 * Author : xuliang
 * Description: RoleUtils
 * <p>
 */
public class RoleUtils {

    private static final Map<Integer, Long> FINANCE_MAP = new HashMap<>();
    private static final Map<Integer, Long> BUDGETER_MAP = new HashMap<>();

    static {
        FINANCE_MAP.put(3, 3L); // FJ_FIANCE
        FINANCE_MAP.put(4, 20L); // HW_FIANCE
        FINANCE_MAP.put(5, 22L); // SZ_FIANCE
        FINANCE_MAP.put(6, 24L); // KF_FIANCE
        FINANCE_MAP.put(7, 26L); // XCD_FIANCE
        FINANCE_MAP.put(8, 28L); // YR_FIANCE

        BUDGETER_MAP.put(3, 2L); // FJ_BUDGETER
        BUDGETER_MAP.put(4, 21L); // HW_BUDGETER
        BUDGETER_MAP.put(5, 23L); // SZ_BUDGETER
        BUDGETER_MAP.put(6, 25L); // KF_BUDGETER
        BUDGETER_MAP.put(7, 27L); // XCD_BUDGETER
        BUDGETER_MAP.put(8, 29L); // YR_BUDGETER
    }

    public static Long getRole(int areaId, String type) {
        if ("F".equals(type)) {
            return FINANCE_MAP.getOrDefault(areaId, -1L); // 默认值为-1
        } else if ("B".equals(type)) {
            return BUDGETER_MAP.getOrDefault(areaId, -1L); // 默认值为-1
        }
        return null;
    }

    public static boolean hasPermission(List<Long> userRoles) {
        for (Long role : userRoles) {
            if (UserConstants.SECTOR_MANAGER_IDS.contains(role)) {
                return true;
            }
        }
        return false;
    }

}
